from pathlib import Path
import os
import locale
from django.conf import settings

BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-wn(4xbq)*zlx&ryg0lf1=u(^7q1er&v1-g-+4$h7^(i%er%0r2'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

# 运行访问的主机
ALLOWED_HOSTS = ["*"]
ROOT_URLCONF = 'NoFish.urls'
# Application definition

# 程序注册
INSTALLED_APPS = [
	'django.contrib.admin',
	'django.contrib.auth',
	'django.contrib.contenttypes',
	'django.contrib.sessions',
	'django.contrib.messages',
	'django.contrib.staticfiles',
	"user.apps.UserConfig",  # 用户模块
	"area.apps.AreaConfig",  # 地区模块
	"article.apps.ArticleConfig",  # 文章模块
	"friends.apps.FriendsConfig",  # 好友模块
	"love.apps.LoveConfig",  # 点赞模块
	"content.apps.ContentConfig",  # 评论模块
]

# 邮箱配置
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.qq.com"  # 腾讯qq地址
EMAIL_PORT = 25
EMAIL_HOST_USER = "2143667305@qq.com"  # 发送方邮箱
EMAIL_HOST_PASSWORD = "srjkffongmprbefi"
EMAIL_USE_SSL = False  # SSL加密

# 中间件
MIDDLEWARE = [
	'django.middleware.security.SecurityMiddleware',
	'django.contrib.sessions.middleware.SessionMiddleware',
	'django.middleware.common.CommonMiddleware',
	# 'django.middleware.csrf.CsrfViewMiddleware', csrf
	'django.contrib.auth.middleware.AuthenticationMiddleware',
	'django.contrib.messages.middleware.MessageMiddleware',
	'django.middleware.clickjacking.XFrameOptionsMiddleware',
	"user.middleware.MyFilter",  # 自定义中间件   过滤器
]

# 模板
TEMPLATES = [
	{
		'BACKEND': 'django.template.backends.django.DjangoTemplates',
		'DIRS': [BASE_DIR / 'templates']
		,
		'APP_DIRS': True,
		'OPTIONS': {
			'context_processors': [
				'django.template.context_processors.debug',
				'django.template.context_processors.request',
				'django.contrib.auth.context_processors.auth',
				'django.contrib.messages.context_processors.messages',
			],
		},
	},
]
ASGI_APPLICATION = "NoFish.asgi.application"
WSGI_APPLICATION = 'NoFish.wsgi.application'

CHANNEL_LAYERS = {
	"default": {
		"BACKEND": "channels.layers.InMemoryChannelLayer"
	}
}
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators


AUTH_PASSWORD_VALIDATORS = [
	{
		'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
	},
	{
		'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
	},
	{
		'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
	},
	{
		'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
	},
]

# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'  # 上海时间
USE_I18N = True
USE_L10N = True
USE_TZ = False

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

# 静态文件地址
STATIC_URL = '/static/'
STATICFILES_DIRS = [
	os.path.join(BASE_DIR, 'static')
]

# 上传文件地址
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
MEDIA_URL = "/uploads/"

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# 数据库
DATABASES = {
	# 默认数据库
	'default': {
		'ENGINE': 'django.db.backends.mysql',
		"NAME": "summer",  # 数据库名
		"USER": "root",  # 登录用户
		"PASSWORD": "qwe123",  # 登录密码
		"HOST": "127.0.0.1",  # 本机
		"PORT": "3306"  # 端口
	}
}

# 缓存
CACHES = {
	"default": {
		"BACKEND": "django_redis.cache.RedisCache",
		"LOCATION": "redis://localhost:6379/2",  # 使用2号索引数据库
		"OPTIONS": {
			"CLIENT_CLASS": "django_redis.client.DefaultClient",
		}
	}
}
